// Database schema types for RBAC system
export interface User {
  id: string
  email: string
  name: string
  avatar?: string
  status: "active" | "inactive" | "suspended"
  createdAt: Date
  updatedAt: Date
  lastLoginAt?: Date
  roleIds: string[]
}

export interface Role {
  id: string
  name: string
  description: string
  color: string
  isSystem: boolean // System roles cannot be deleted
  createdAt: Date
  updatedAt: Date
  permissionIds: string[]
}

export interface Permission {
  id: string
  name: string
  description: string
  resource: string // e.g., 'users', 'roles', 'permissions'
  action: string // e.g., 'create', 'read', 'update', 'delete'
  isSystem: boolean
  createdAt: Date
  updatedAt: Date
}

export interface UserRole {
  userId: string
  roleId: string
  assignedAt: Date
  assignedBy: string
}

export interface RolePermission {
  roleId: string
  permissionId: string
  grantedAt: Date
  grantedBy: string
}

// Auth context types
export interface AuthUser {
  id: string
  email: string
  name: string
  avatar?: string
  roles: Role[]
  permissions: Permission[]
}

export interface AuthContextType {
  user: AuthUser | null
  login: (email: string, password: string) => Promise<boolean>
  logout: () => void
  hasPermission: (resource: string, action: string) => boolean
  hasRole: (roleName: string) => boolean
  isLoading: boolean
}

// API response types
export interface ApiResponse<T> {
  success: boolean
  data?: T
  error?: string
  message?: string
}

export interface PaginatedResponse<T> {
  data: T[]
  total: number
  page: number
  limit: number
  totalPages: number
}

// Form types
export interface CreateUserForm {
  email: string
  name: string
  password: string
  roleIds: string[]
}

export interface UpdateUserForm {
  name: string
  email: string
  roleIds: string[]
  status: "active" | "inactive" | "suspended"
}

export interface CreateRoleForm {
  name: string
  description: string
  color: string
  permissionIds: string[]
}

export interface UpdateRoleForm {
  name: string
  description: string
  color: string
  permissionIds: string[]
}
